package cn.baizhi.service.impl;

import cn.baizhi.entity.Clazz;
import cn.baizhi.entity.Group;
import cn.baizhi.feign.ClazzClient;
import cn.baizhi.mapper.GroupMapper;
import cn.baizhi.service.GroupService;
import cn.baizhi.vo.GroupDTO;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author LZM
 * @since 2021-12-03
 */
@Service
public class GroupServiceImpl extends ServiceImpl<GroupMapper, Group> implements GroupService {

    @Autowired
    private GroupMapper groupMapper;

    @Autowired
    private ClazzClient clazzClient;

    @Override
    public List<GroupDTO> selectAll() {
        List<Group> groups = groupMapper.selectList(null);

        List<GroupDTO> list = new ArrayList<>();

        for (Group group : groups) {
            ResponseEntity<Clazz> clazzResponseEntity = clazzClient.selectOne(group.getClazzId());
            list.add(new GroupDTO(group.getId(),group.getName(),group.getCreateDate(),clazzResponseEntity.getBody()));

        }

        return list;
    }
}
